home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / PUTC.ASM < prev    next >
Assembly Source File  |  1991-12-04  |  3KB  |  156 lines

  1. ;
  2. StdGrp        group    StdLib, StdData
  3. ;
  4. StdData        segment    para public 'sldata'
  5. ;
  6. PutcAdrs    dd    stdgrp:sl_putcstdout
  7. PutcStkIndx    dw    0
  8. PutcStk        dd    16 dup (stdgrp:sl_putcstdout)
  9. PSIsize        =    $-PutcStk
  10. StdData        ends
  11. ;
  12. stdlib        segment    para public 'slcode'
  13.         assume    cs:StdGrp,ds:nothing
  14. ;
  15. ;
  16. ;
  17. ; Putc- Sends the character in AL to the current output routine.
  18. ;    By default, this is "putstdout".  PutcAdrs contains the address of the
  19. ;    current output routine.
  20. ;
  21.         public    sl_putc
  22. sl_putc        proc    far
  23.         jmp    dword ptr StdGrp:PutcAdrs
  24. sl_putc        endp
  25. ;
  26. ;
  27. ;
  28. ;
  29. ; PutCR-    Prints a new line to the standard output device.
  30. ;
  31.         public    sl_putcr
  32. sl_putcr    proc    far
  33.         push    ax
  34.         mov    al, 13        ;Carriage return
  35.         call    dword ptr StdGrp:PutcAdrs
  36.         mov    al, 10        ;Line feed
  37.         call    dword ptr StdGrp:PutcAdrs
  38.         pop    ax
  39.         ret
  40. sl_putcr    endp
  41. ;
  42. ;
  43. ;
  44. ; PutStdOut- Prints the character in AL to the standard output device by
  45. ;         calling DOS to print the character.
  46. ;
  47.         public    sl_putcstdout
  48. sl_putcstdout    proc    far
  49.         push    ax
  50.         push    dx
  51.         mov    dl, al
  52.         mov    ah, 2
  53.         int    21h
  54.         pop    dx
  55.         pop    ax
  56.         ret
  57. sl_putcstdout    endp
  58. ;
  59. ;
  60. ; PutcBIOS-    Prints the character in AL by calling the BIOS output routine.
  61. ;
  62.         public    sl_PutcBIOS
  63. sl_PutcBIOS    proc    far
  64.         push    ax
  65.         mov    ah, 14
  66.         int    10h
  67.         pop    ax
  68.         ret
  69. sl_PutcBIOS    endp
  70. ;
  71. ;
  72. ; GetOutAdrs-    Returns the address of the current output routine in ES:DI.
  73. ;
  74.         public    sl_GetOutAdrs
  75. sl_GetOutAdrs    proc    far
  76.         les    di, StdGrp:PutcAdrs
  77.         ret
  78. sl_GetOutAdrs    endp
  79. ;
  80. ;
  81. ; SetOutAdrs-    Stores the address in ES:DI into PutcAdrs.  This must be the
  82. ;        address of a valid output routine which outputs the character
  83. ;        in the AL register.  This routine must preserve all registers.
  84. ;
  85.         public    sl_SetOutAdrs
  86. sl_SetOutAdrs    proc    far
  87.         mov    word ptr StdGrp:PutcAdrs, di
  88.         mov    word ptr StdGrp:PutcAdrs+2, es
  89.         ret
  90. sl_SetOutAdrs    endp
  91. ;
  92. ;
  93. ;
  94. ; PushOutAdrs-    Pushes the current output address onto the output stack
  95. ;        and then stores the address in es:di into the output address
  96. ;        pointer.  Returns carry clear if no problems.  Returns carry
  97. ;        set if there is an address stack overflow.  Does NOT modify
  98. ;        anything if the stack is full.
  99. ;
  100.         public    sl_PushOutAdrs
  101. sl_PushOutAdrs    proc    far
  102.         push    ax
  103.         push    di
  104.         cmp    StdGrp:PutcStkIndx, PSIsize
  105.         jae    BadPush
  106.         mov    di, StdGrp:PutcStkIndx
  107.         add    StdGrp:PutcStkIndx, 4
  108.         mov    ax, word ptr StdGrp:PutcAdrs
  109.         mov    word ptr StdGrp:PutcStk[di], ax
  110.         mov    ax, word ptr StdGrp:PutcAdrs+2
  111.         mov    word ptr StdGrp:PutcStk+2[di], ax
  112.         pop    di
  113.         mov    word ptr StdGrp:PutcAdrs, di
  114.         mov    word ptr StdGrp:PutcAdrs+2, es
  115.         pop    ax
  116.         clc
  117.         ret
  118. ;
  119. BadPush:    pop    di
  120.         pop    ax
  121.         stc
  122.         ret
  123. sl_PushOutAdrs    endp
  124. ;
  125. ;
  126. ; PopOutAdrs-    Pops an output address off of the stack and stores it into
  127. ;        the PutcAdrs variable.
  128. ;
  129.         public    sl_PopOutAdrs
  130. sl_PopOutAdrs    proc    far
  131.         push    ax
  132.         mov    di, StdGrp:PutcStkIndx
  133.         sub    di, 4
  134.         jns    GoodPop
  135. ;
  136. ; If this guy just went negative, set it to zero and push the address
  137. ; of the stdout routine onto the stack.
  138. ;
  139.         xor    di, di            
  140.         mov    word ptr StdGrp:PutcStk, offset stdgrp:sl_PutcStdOut
  141.         mov    word ptr StdGrp:PutcStk+2, stdgrp
  142. ;
  143. GoodPop:    mov    StdGrp:PutcStkIndx, di
  144.         mov    es, word ptr PutcAdrs+2
  145.         mov    ax, word ptr StdGrp:PutcStk+2[di]
  146.         mov    word ptr StdGrp:PutcAdrs+2, ax
  147.         mov    ax, word ptr StdGrp:PutcStk[di]
  148.         xchg    word ptr StdGrp:PutcAdrs, ax
  149.         mov    di, ax
  150.         pop    ax
  151.         ret
  152. sl_PopOutAdrs    endp
  153. ;
  154. stdlib        ends
  155.         end
  156.